/*
 * KudoGDX is a 2D game development library.
 * It wraps LibGDX, Apache MINA/Codec and a young but efficient GUI implementation.
 */
package com.kudo.gdx.ui;

import com.badlogic.gdx.InputMultiplexer;

/**
 *
 * @author Ike
 */
public class MultiInputProcessor extends InputMultiplexer {

    private Component comp = null;

    public MultiInputProcessor(Component c) {
        super();
        comp = c;
    }

    @Override
    public boolean keyDown(int keycode) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).keyDown(keycode)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).keyUp(keycode)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).keyTyped(character)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).touchDown(screenX, screenY, pointer, button)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).touchUp(screenX, screenY, pointer, button)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).touchDragged(screenX, screenY, pointer)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).mouseMoved(screenX, screenY)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        if (comp.getEnabled() && comp.getVisible()) {
            for (int i = 0, n = getProcessors().size; i < n; i++) {
                if (getProcessors().get(i).scrolled(amount)) {
                    return true;
                }
            }
        }
        return false;
    }
}
